package test.graph;

import java.io.IOException;
import java.util.Scanner;

/**
 * @brief  无向图 v:端点 e:边
 *
 * @author linshuo
 *
 */
public class GraphDef {
    public static void main(String[] args) throws IOException {
        Scanner cin = new Scanner(System.in);

        int v = cin.nextInt();
        int e = cin.nextInt();

        Graph g = new Graph(v, e);

        for (int i = 0; i < e; i++) {
            int a = cin.nextInt();
            int b = cin.nextInt();
            g.addEdge(a, b);
        }
        cin.close();
    }
}

class Graph {
    int v;      // 端点
    int e;      // 边
    ListHead[] vertex;

    public Graph(int v, int e) {
        this.v = v;
        this.e = e;
        vertex = new ListHead[v + 1];

        for (int i = 1; i <= v; i++) {
            vertex[i] = new ListHead(i);
        }
    }

    public void addEdge(int a, int b) {
        vertex[a].linkTo(b);
        vertex[b].linkTo(a);
    }
}

/**
 * @brief  单向链表节点
 *
 * @author linshuo
 *
 */
class AdjacentListNode {
    public int nodeIndex;
    public int info;
    public AdjacentListNode nextArc;

    public AdjacentListNode(int nodeIndex) {
        this.nodeIndex = nodeIndex;
        nextArc = null;
    }
}

class ListHead {
    int data;
    AdjacentListNode firstArc;

    public boolean visited;

    public ListHead(int data) {
        this.data = data;
        visited = false;
    }

    public void linkTo(int end) {
        if (firstArc == null) {
            firstArc = new AdjacentListNode(end);
            return;
        }

        AdjacentListNode n = firstArc;
        while (n.nextArc != null) {
            n = n.nextArc;
        }

        n.nextArc = new AdjacentListNode(end);
    }
}

